﻿drop table [dimdata]
drop table [dimitem]
drop table [docdef]
drop table [docdim]

create table dimdata(
	id uniqueidentifier,
	code nvarchar(64),
	name nvarchar(64),
	primary key (id)
)

create table dimitem(
	id uniqueidentifier,
	code nvarchar(64),
	name nvarchar(64),
	dataid uniqueidentifier,
	parentid uniqueidentifier,
	primary key (id)
)

create table docdef(
	id uniqueidentifier,
	code nvarchar(64),
	name nvarchar(64),
	primary key(id)
)

create table docdim(
	id uniqueidentifier,
	docid uniqueidentifier,
	dimid uniqueidentifier,
	dimcode nvarchar(64),
	dimname nvarchar(64),
	[index] int,
	[direction] char,
	[dirindex] int,
	ispagedim bit,
	primary key(id)
)

create table doctemplate(
	id uniqueidentifier,
	yearid uniqueidentifier,
	bdid uniqueidentifier,
	orgid uniqueidentifier,
	defid uniqueidentifier,
	code nvarchar(64),
	name nvarchar(64),
	[version] nvarchar(64),
	islatest bit,
	[data] text,
	primary key(id)
)

create table docinstance(
	id uniqueidentifier,
	yearid uniqueidentifier,
	bdid uniqueidentifier,
	orgid uniqueidentifier,
	templateid uniqueidentifier,
	filepath nvarchar(255),
	name nvarchar(32),
	primary key(id)
)

create table byear(
	id uniqueidentifier,
	name nvarchar(32),
	primary key(id)
)

create table bdomain(
	id uniqueidentifier,
	name nvarchar(32),
	parentid uniqueidentifier,
	primary key(id)
)

create table borg(
	id uniqueidentifier,
	name nvarchar(32),
	parentid uniqueidentifier,
	primary key(id)
)